package com.haoting.mamba.ucenter.util;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;

import javax.mail.internet.MimeMessage;
import java.io.StringWriter;

@Component
public class EmailUtil {
    //通过JavaMailSenderImpl中的无参构造方法，从而调用MailSenderPropertiesConfiguration类，通过mailSender方法中this.applyProperties即可
    @Autowired
    private JavaMailSenderImpl mailSender;

    @Autowired
    TemplateEngine templateEngine;

    /**
     * 发送包含简单文本的邮件
     */
    public  String  sendTxtMail(String email,String message) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        // 设置收件人邮箱
        simpleMailMessage.setTo(new String[] {email});
        //设置寄件人邮箱
        simpleMailMessage.setFrom("767417609@qq.com");
        simpleMailMessage.setSubject("验证码校验");
        simpleMailMessage.setText("你的验证码为"+message+"验证码的有效期为1分钟");
        // 发送邮件
        mailSender.send(simpleMailMessage);

        return "邮件已发送";
    }


}


